<template>
  <div id="app-container" style="margin: 20px">
    <!--条件查询表单-->
    <el-form :inline="true">

      <el-form-item label="商品订单编号">
        <el-input v-model="paymentInfoDTO.orderNo" size="small" placeholder="商品订单编号"/>
      </el-form-item>

      <el-form-item label="支付系统交易编号">
        <el-input v-model="paymentInfoDTO.transactionId" size="small" placeholder="支付系统交易编号"/>
      </el-form-item>

      <el-form-item label="支付金额">
        <el-input v-model="paymentInfoDTO.payerTotal" size="small" placeholder="请选择支付金额"/>
      </el-form-item>

      <!--      <el-form-item label="支付金额">-->
      <!--        <el-input v-model="paymentInfoDTO.payerTotal" size="small" placeholder="支付金额"/>-->
      <!--      </el-form-item>-->

    </el-form>

    <el-form :inline="true">
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="paymentInfoDTO.createTimeStart"
          size="small"
          type="datetime"
          placeholder="选择开始时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          default-time="00:00:00"/>
      </el-form-item>
      <el-form-item>
        <el-date-picker
          v-model="paymentInfoDTO.createTimeEnd"
          size="small"
          type="datetime"
          placeholder="选择截止时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          default-time="00:00:00"/>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="pageListQuery()">搜索</el-button>
        <el-button plain icon="el-icon-refresh" size="small" style="margin-left: 0" @click="resetData()">清空</el-button>

      </el-form-item>
    </el-form>

    <el-form :inline="true">
      <!--      <router-link to="/paymentInfo/add">-->
      <!--        <el-button type="primary" plain icon="el-icon-plus" size="small">新增</el-button>-->
      <!--      </router-link>-->
      <!--      <el-button type="warning" plain icon="el-icon-delete" size="small" @click="deleteBySelect">批量删除</el-button>-->
      <el-button type="danger" plain icon="el-icon-download" size="small" @click="handleExport">导出</el-button>
    </el-form>

    <!--数据显示列表-->
    <el-table
      :data="paymentInfoList"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange">
      <el-table-column
        type="selection"
        width="45"
        align="center"/>
      <el-table-column label="序号" width="50" align="center">
        <template slot-scope="scope">
          {{ (currentPage - 1) * pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <!--      <el-table-column prop="id" label="靶场分级ID" width="90" align="center"/>-->

      <el-table-column prop="orderNo" label="商户订单编号" width="280" align="center"/>

      <el-table-column prop="transactionId" label="支付系统交易编号" width="280" align="center"/>

      <el-table-column prop="paymentType" label="支付类型" align="center"/>

      <el-table-column prop="payerTotal" label="支付金额" align="center"/>

      <!--      <el-table-column prop="content" label="通知参数" align="center"/>-->

      <el-table-column prop="createTime" label="创建时间" width="200" align="center"/>
      <el-table-column prop="updateTime" label="更新时间" width="200" align="center"/>

      <!--      <el-table-column label="操作" align="center">-->
      <!--        <template slot-scope="scope">-->
      <!--          <router-link :to="'/trainingLevel/update/'+scope.row.id">-->
      <!--            <el-button-->
      <!--              type="text"-->
      <!--              icon="el-icon-edit"-->
      <!--              size="mini">编辑</el-button>-->
      <!--          </router-link>-->
      <!--          <el-button-->
      <!--            size="mini"-->
      <!--            type="text"-->
      <!--            icon="el-icon-delete"-->
      <!--            @click="handleDelete(scope.row.id)">删除-->
      <!--          </el-button>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
    </el-table>
    <div class="block">
      <el-pagination
        :current-page="currentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pageSize"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"/>
    </div>
  </div>
</template>

<script>
import paymentInfo from '../../api/paymentInfo'
import axios from 'axios'
import fileDownload from 'js-file-download'

export default {
  data() {
    return {
      paymentInfoDTO: {},
      paymentInfoList: [],
      currentPage: 1,
      pageSize: 10,
      total: 1,
      ids: [],
      multipleSelection: ['']
    }
  },
  created() {
    this.initDate()
  },
  methods: {
    pageListQuery() {
      this.initDate()
    },
    resetData() {
      this.paymentInfoDTO = {}
      this.initDate()
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.pageSize = val
      this.initDate()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.currentPage = val
      this.initDate()
    },
    handleDelete(id) {
      this.$confirm('是否确定删除', '提示信息', { type: 'warning' }).then(() => {
        this.ids.push(id)
        paymentInfo.deleteOneTrainingLevel(this.ids).then(response => {
          this.$message.success('删除成功')
          this.initDate()
          this.ids = []
        })
      }).catch(() => {
        this.$message.info('取消删除操作')
      })
    },
    handleSelectionChange(val) {
      console.log(val)
      this.multipleSelection = []
      for (let i = 0; i < val.length; i++) {
        if (this.multipleSelection.indexOf(val[i].id) === -1) {
          this.multipleSelection.push(val[i].id)
        }
      }
      console.log(this.multipleSelection)
    },
    deleteBySelect() {
      this.$confirm('是否确定删除', '提示信息', { type: 'warning' }).then(() => {
        paymentInfo.deleteSelectTrainingLevel(this.multipleSelection).then(response => {
          this.$message.success('删除成功')
          this.multipleSelection = []
          this.initDate()
        })
      }).catch(() => {
        this.$message.info('取消删除操作')
      })
    },
    handleExport() {
      axios({
        method: 'post',
        url: 'http://localhost:8080/paymentInfo/export',
        responseType: 'blob',
        data: this.paymentInfoDTO
      }).then(res => {
        if (res && res.data) {
          fileDownload(res.data, '支付信息.xlsx')
        }
      })
    },
    initDate() {
      paymentInfo.listPage(this.currentPage, this.pageSize, this.paymentInfoDTO).then(response => {
        this.paymentInfoList = response.data.data
        this.total = response.data.total
      })
    }
  }
}
</script>
